package com.zzyl.nursing.controller.member;

import java.util.List;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.AddFamilyMemberRequestDto;
import com.zzyl.nursing.dto.DeviceDataListDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.service.IFamilyMemberService;

@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {

    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    @ApiOperation("老人家属的登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }
    @PostMapping("/add")
    @ApiOperation("老人家属的登录")
    public AjaxResult login(@RequestBody AddFamilyMemberRequestDto dto) {
        familyMemberService.addFamilyRelation(dto);
        return AjaxResult.success();
    }

    //查询家人列表
    @GetMapping("/my")
    public AjaxResult getFamilyElderList() {

        List<FamilyMemberVo> list = familyMemberService.getFamilyElderList();
        return AjaxResult.success(list);

    }
    // 查询健康数据
    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties(@PathVariable String iotId) {
        List<DeviceDataVo> list = familyMemberService.queryServiceProperties(iotId);
        return AjaxResult.success(list);
    }
    @GetMapping("/list-by-page")
    public AjaxResult listByPage(Integer pageNum, Integer pageSize) {
        startPage();
        List<FamilyMemberElderVo> list = familyMemberService.listByPage();
        return AjaxResult.success(list);
    }

    // 按天统计查询指标数据
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(DeviceDataListDto dto) {
        List<DeviceDataByDayVo> result = familyMemberService.queryDeviceDataListByDay(dto);
        return AjaxResult.success(result);
    }

    // 按周统计查询指标数据
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(DeviceDataListDto dto) {
        List<DeviceDataByWeekVo> result = familyMemberService.queryDeviceDataListByWeek(dto);
        return AjaxResult.success(result);
    }
    @DeleteMapping("deleteById")
    public AjaxResult deleteById(@RequestParam Integer id) {
        familyMemberService.deleteById(id);
        return AjaxResult.success();
    }
}
